Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(web): add e2e test example to visualizer #1140

Merged
merged 12 commits into from
Sep 13, 2024
Merged

test(web): add e2e test example to visualizer #1140

merged 12 commits into from
Sep 13, 2024

Conversation

ZTongci
Copy link
Contributor

@ZTongci ZTongci commented Sep 11, 2024

Overview

add e2e test example to visualizer

What I've done

create session once and use this session to login and testing.
add pom structure for e2e test.
add e2e test example to visualizer that create layer and add circle into earth.

What I haven't done

I don't change old e2e test structure. And didn't use auth0 login function.

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features

    • Added a new test script for creating a project and adding a layer, including visual validation through screenshots.
    • Implemented a structured interface for interacting with map visualization components in end-to-end testing.
    • Introduced new environment variables to support end-to-end testing configurations.
  • Bug Fixes

    • Disabled an inactive test case for logging into the dashboard to prevent misleading results.
  • Documentation

    • Enhanced module exports for better organization and accessibility of components related to project and map functionalities.
  • Chores

    • Updated .gitignore to exclude sensitive files and directories from version control.
    • Improved Playwright configuration for enhanced test execution and debugging.

Copy link

coderabbitai bot commented Sep 11, 2024

Walkthrough

The changes introduce enhancements to the end-to-end testing framework for a web application. Updates include modifications to the .gitignore file to exclude sensitive files, the commenting out of a test case in the dashboard, and the addition of new test scripts. New classes and modules have been created for better interaction with the map visualization and project management functionalities. Additionally, comments have been added to indicate unused files, and new environment variables for testing have been introduced.

Changes

Files Change Summary
web/.gitignore Added e2e/utils/.auth and e2e/testSnapshot to ignore sensitive files and reduce repository clutter.
web/.env.example Added new environment variables for E2E testing: REEARTH_WEB_E2E_BASEURL, REEARTH_WEB_E2E_ACCOUNT, and REEARTH_WEB_E2E_ACCOUNT_PASSWORD.
web/e2e/dashboard.spec.ts Commented out the entire test case for logging into the dashboard, disabling it.
web/e2e/editorMapAddLayer.spec.ts Added a new end-to-end test for creating a project and adding a layer, including visual validation through screenshots.
web/e2e/pom/visualizer/editor/MapPage.ts Introduced a MapPage class for interacting with the map visualization component, including methods for layer creation and manipulation.
web/e2e/pom/visualizer/editor/index.ts Created an index file to export the MapPage component for easier access.
web/e2e/pom/visualizer/index.ts Created an entry point for exporting visualizer-related modules, including dashboard, editor, and projectSetting.
web/e2e/utils/config.ts Added a comment indicating that the config object is currently not in use.
web/e2e/utils/login.ts Added a comment stating that the file is "not in use."
web/e2e/utils/setup.ts Added a comment indicating that the file is "not in use."
web/e2e/utils/index.ts Enhanced exports to include chromium, Page, and Locator types alongside expect.
web/playwright.config.ts Updated configuration to include device settings, added timeout, headless property, modified globalSetup, and introduced projects for "chromium" settings.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AuthSetup
    participant Browser
    participant Dashboard
    participant ProjectsPage
    participant MapPage

    User->>AuthSetup: Validate credentials
    AuthSetup->>Browser: Launch Chromium
    Browser->>AuthSetup: Navigate to base URL
    AuthSetup->>Browser: Fill login form
    Browser->>AuthSetup: Submit form
    AuthSetup->>Browser: Wait for page load
    Browser->>AuthSetup: Verify "New Project" button
    AuthSetup->>Browser: Save storage state
    Browser->>User: Close browser
Loading

🐇 "In the garden where changes bloom,
New scripts and pages make room.
With projects and layers, we hop and play,
Testing the app in a joyful way!
So let’s celebrate with a cheer,
For every change brings us near!" 🥕

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Sep 11, 2024

Deploy Preview for reearth-web canceled.

Name Link
🔨 Latest commit 4042d4b
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/66e3fb6959dfe30008872644

@github-actions github-actions bot added the web label Sep 11, 2024
@ZTongci ZTongci changed the title feat : add e2e test example to visualizer feat: add e2e test example to visualizer Sep 11, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range and nitpick comments (2)
web/playwright.config.ts (1)

11-12: LGTM, but consider running tests in headless mode for faster execution.

The changes to the use object are approved.

  • Setting headless to false can be useful for debugging but may slow down test execution. Consider running tests in headless mode for faster execution and only enabling the visible browser window when needed for debugging.
  • Setting video to "retain-on-failure" is a good practice to save storage space.
web/e2e/auth.setup.ts (1)

21-33: Consider improving the wait strategy after login.

The browser launch and login process are correctly implemented. However, the 10-second wait after logging in might be unnecessary or too long.

Instead of waiting for a fixed duration, consider waiting for a specific condition that indicates the successful login, such as the appearance of a particular element on the page. For example:

-await page.waitForTimeout(10 * 1000);
+await expect(page.getByRole("button", { name: "New Project" })).toBeVisible();

This way, the test will proceed as soon as the expected element is visible, making the test more efficient and reliable.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c18275f and 4c6bffa.

Files ignored due to path filters (1)
  • web/e2e/README.md is excluded by !**/*.md
Files selected for processing (13)
  • web/e2e/auth.setup.ts (1 hunks)
  • web/e2e/dashboard.spec.ts (1 hunks)
  • web/e2e/example.spec.ts (1 hunks)
  • web/e2e/pom/index.ts (1 hunks)
  • web/e2e/pom/visualizer/dashboard/ProjectsPage.ts (1 hunks)
  • web/e2e/pom/visualizer/dashboard/index.ts (1 hunks)
  • web/e2e/pom/visualizer/index.ts (1 hunks)
  • web/e2e/pom/visualizer/projectSetting/generalPage.ts (1 hunks)
  • web/e2e/pom/visualizer/projectSetting/index.ts (1 hunks)
  • web/e2e/pom/visualizer/scene/MapPage.ts (1 hunks)
  • web/e2e/pom/visualizer/scene/index.ts (1 hunks)
  • web/e2e/utils/index.ts (1 hunks)
  • web/playwright.config.ts (1 hunks)
Files skipped from review due to trivial changes (6)
  • web/e2e/dashboard.spec.ts
  • web/e2e/pom/index.ts
  • web/e2e/pom/visualizer/dashboard/index.ts
  • web/e2e/pom/visualizer/index.ts
  • web/e2e/pom/visualizer/projectSetting/index.ts
  • web/e2e/pom/visualizer/scene/index.ts
Additional comments not posted (24)
web/e2e/pom/visualizer/projectSetting/generalPage.ts (2)

3-28: LGTM!

The generalPage class is well-structured and follows the Page Object Model (POM) pattern for organizing the interactions with the general project settings page. The class encapsulates the page-specific elements and actions, making the tests more readable and maintainable.


7-15: LGTM!

The constructor correctly initializes the page property and locates the project name element using a specific selector. The locator is resilient to changes in the page structure, making the tests more maintainable.

web/playwright.config.ts (3)

1-1: LGTM!

The change to the import statement is approved.


18-32: LGTM!

The addition of the projects property is approved.

  • Defining multiple project configurations can be useful for running tests across different environments or devices.
  • The configuration for "chromium" looks good and includes reasonable options for running tests.

15-16: LGTM, but verify the implementation of the new setup file.

The change to the globalSetup property is approved.

However, ensure that the new setup file ./e2e/auth.setup.ts is implemented correctly and provides the necessary setup for the tests.

Run the following script to verify the implementation of the new setup file:

web/e2e/pom/visualizer/dashboard/ProjectsPage.ts (5)

9-14: LGTM!

The constructor is correctly initializing the ProjectsPage class with the required Page object and locators.


16-18: LGTM!

The goto method is correctly navigating to the root URL.


20-24: LGTM!

The createProject method is correctly creating a new project by interacting with the new project button, project name input, and apply button.


26-30: LGTM!

The dbClickInProjectByName method is correctly double-clicking on a project with the given name.


32-38: LGTM!

The intoProjectSettingByName method is correctly navigating to the project settings page for a project with the given name.

web/e2e/auth.setup.ts (2)

1-19: LGTM!

The imports and environment variable handling look good:

  • The necessary dependencies are imported correctly.
  • Reading the account credentials from environment variables is a secure approach.
  • Throwing an error when the required variables are missing is a good practice to prevent unexpected behavior.

34-40: LGTM!

Storing the authenticated session state is correctly implemented:

  • Saving the session state to a file allows reusing the session across multiple tests.
  • Using __dirname to construct the file path ensures that the file is saved in the correct location.
  • The .json file extension indicates that the session state is saved in a standard and interoperable format.
web/e2e/pom/visualizer/scene/MapPage.ts (6)

12-24: LGTM!

The constructor is well-structured and initializes the locators for various elements on the page using appropriate methods based on the element's attributes. The locators are stored as instance variables, making them accessible to other methods in the class.


26-28: LGTM!

The goto method is simple and straightforward, navigating to the root URL of the application.


30-36: LGTM!

The createNewLayerBySketch method automates the process of creating a new layer by sketch. It performs the necessary actions in the correct order and waits for the "New Layer" button to be visible before proceeding, ensuring that the page has loaded properly. The method takes the layer name as a parameter, making it reusable for creating different layers.


38-44: LGTM!

The getLocatorOfCanvs method is useful for retrieving the coordinates of the center of the canvas, which can be used for performing actions on the canvas, such as creating a circle. The method throws an error if no canvas is found, providing a clear indication of the issue.


46-52: LGTM!

The createCircleToEarthByLocator method automates the process of creating a circle on the earth using the specified coordinates. The method performs the necessary actions in the correct order, including waiting for 5 seconds after the first click to allow the earth to load properly. The method also adds a delay of 500 milliseconds to the second click to ensure that the circle is created properly.


54-57: LGTM!

The closeSkyBox method automates the process of closing the sky box. It performs the necessary actions in the correct order, first clicking on the "Sky" text to open the sky box options and then clicking on the sky box select button to close the sky box.

web/e2e/example.spec.ts (4)

1-10: LGTM!

The imports and constants are correctly defined.


12-16: LGTM!

The session setup code is correctly implemented.


45-59: LGTM!

The visual regression testing code is correctly implemented.


61-67: LGTM!

The project deletion code is correctly implemented.

web/e2e/utils/index.ts (2)

Line range hint 1-10: LGTM!

The changes to import chromium and Locator from Playwright are approved.

Importing these additional types and the browser instance enhances the testing capabilities by providing access to useful Playwright APIs.

Disabling ESLint for chromium import is acceptable as it may be re-exported for use in other files.


16-16: LGTM!

The changes to re-export expect, chromium, Page, and Locator from Playwright are approved.

Re-exporting these types and functions allows them to be imported from this file in other parts of the codebase, which enhances the usability and maintainability of the testing setup.

web/playwright.config.ts Show resolved Hide resolved
web/e2e/example.spec.ts Outdated Show resolved Hide resolved
@airslice airslice changed the title feat: add e2e test example to visualizer test(web): add e2e test example to visualizer Sep 12, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
web/e2e/editorMapAddLayer.spec.ts (1)

18-68: Great test structure! Consider improving the reliability and configurability of the screenshot comparison.

The test case follows a clear structure and uses a Page Object Model (POM) for interacting with the application, which is a good practice for maintainability and readability. The use of unique identifiers for the project and layer names, waiting for the canvas to stabilize before taking the screenshot, deleting the created project at the end, using environment variables for the base URL, and using a session stored in a JSON file for authentication are all good practices.

However, there are a few areas that could be improved:

  1. The test case uses a hardcoded timeout of 5 seconds for waiting for the canvas to stabilize. This can be brittle and may need to be adjusted based on the performance of the application. Consider using a more reliable way to wait for the canvas to stabilize, such as waiting for a specific element to be visible or for the network requests to complete.

  2. The test case uses a hardcoded value of 10 for the maximum number of different pixels allowed in the screenshot comparison. This may need to be adjusted based on the expected level of variance in the rendering. Consider making this value configurable, either through an environment variable or a configuration file.

  3. The test case uses a soft assertion for comparing the screenshot with the expected image, which allows the test to continue even if the assertion fails. While this can be useful for debugging, it's important to ensure that the test fails if any assertion fails. Consider adding a check after the soft assertion to fail the test if the assertion failed.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4c6bffa and 3261d87.

Files ignored due to path filters (1)
  • web/e2e/editorMapAddLayer.spec.ts-snapshots/editorMapAddLayerExpect-chromium-darwin.png is excluded by !**/*.png
Files selected for processing (9)
  • web/.gitignore (1 hunks)
  • web/e2e/dashboard.spec.ts (1 hunks)
  • web/e2e/editorMapAddLayer.spec.ts (1 hunks)
  • web/e2e/pom/visualizer/editor/MapPage.ts (1 hunks)
  • web/e2e/pom/visualizer/editor/index.ts (1 hunks)
  • web/e2e/pom/visualizer/index.ts (1 hunks)
  • web/e2e/utils/config.ts (1 hunks)
  • web/e2e/utils/login.ts (1 hunks)
  • web/e2e/utils/setup.ts (1 hunks)
Files skipped from review due to trivial changes (6)
  • web/.gitignore
  • web/e2e/dashboard.spec.ts
  • web/e2e/pom/visualizer/editor/index.ts
  • web/e2e/utils/config.ts
  • web/e2e/utils/login.ts
  • web/e2e/utils/setup.ts
Files skipped from review as they are similar to previous changes (1)
  • web/e2e/pom/visualizer/index.ts
Additional comments not posted (1)
web/e2e/pom/visualizer/editor/MapPage.ts (1)

1-58: LGTM!

The MapPage class follows the Page Object Model (POM) pattern and uses Playwright's recommended approaches for interacting with the page. The class contains methods for common actions in the visualizer, such as creating a new layer, creating a circle on the earth, and closing the sky box. The class uses appropriate selectors, waiting mechanisms, mouse actions, error handling, and naming conventions, making the code readable and maintainable.

@airslice airslice merged commit ff37246 into main Sep 13, 2024
12 checks passed
@airslice airslice deleted the feat/e2e_test branch September 13, 2024 08:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (2)
web/playwright.config.ts (2)

12-12: Ensure tests are run in both headless and non-headless modes.

Running tests in a visible browser window by setting headless to false can be useful for debugging purposes. However, it's important to ensure that tests are also run in headless mode, especially in CI/CD pipelines, to catch any issues that may occur specifically in headless mode.

Consider adding a configuration option to control the headless setting based on the environment (e.g., process.env.CI) to automatically run tests in headless mode in CI/CD pipelines.


29-29: Use --no-sandbox with caution.

The launchOptions.args property includes the --no-sandbox argument, which disables the sandboxing feature. While this may be necessary for certain environments, it's important to be aware of the potential security implications.

Disabling the sandbox may make the browser more vulnerable to security threats. Consider enabling the sandbox whenever possible and only disable it when absolutely necessary. If the sandbox must be disabled, ensure that appropriate security measures are in place to mitigate any risks.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 04701d2 and 4042d4b.

Files ignored due to path filters (1)
  • web/e2e/README.md is excluded by !**/*.md
Files selected for processing (18)
  • web/.env.example (1 hunks)
  • web/.gitignore (1 hunks)
  • web/e2e/auth.setup.ts (1 hunks)
  • web/e2e/dashboard.spec.ts (1 hunks)
  • web/e2e/editorMapAddLayer.spec.ts (1 hunks)
  • web/e2e/pom/index.ts (1 hunks)
  • web/e2e/pom/visualizer/dashboard/ProjectsPage.ts (1 hunks)
  • web/e2e/pom/visualizer/dashboard/index.ts (1 hunks)
  • web/e2e/pom/visualizer/editor/MapPage.ts (1 hunks)
  • web/e2e/pom/visualizer/editor/index.ts (1 hunks)
  • web/e2e/pom/visualizer/index.ts (1 hunks)
  • web/e2e/pom/visualizer/projectSetting/generalPage.ts (1 hunks)
  • web/e2e/pom/visualizer/projectSetting/index.ts (1 hunks)
  • web/e2e/utils/config.ts (1 hunks)
  • web/e2e/utils/index.ts (1 hunks)
  • web/e2e/utils/login.ts (1 hunks)
  • web/e2e/utils/setup.ts (1 hunks)
  • web/playwright.config.ts (1 hunks)
Files skipped from review due to trivial changes (7)
  • web/e2e/pom/index.ts
  • web/e2e/pom/visualizer/dashboard/index.ts
  • web/e2e/pom/visualizer/editor/index.ts
  • web/e2e/pom/visualizer/projectSetting/index.ts
  • web/e2e/utils/config.ts
  • web/e2e/utils/login.ts
  • web/e2e/utils/setup.ts
Files skipped from review as they are similar to previous changes (10)
  • web/.env.example
  • web/.gitignore
  • web/e2e/auth.setup.ts
  • web/e2e/dashboard.spec.ts
  • web/e2e/editorMapAddLayer.spec.ts
  • web/e2e/pom/visualizer/dashboard/ProjectsPage.ts
  • web/e2e/pom/visualizer/editor/MapPage.ts
  • web/e2e/pom/visualizer/index.ts
  • web/e2e/pom/visualizer/projectSetting/generalPage.ts
  • web/e2e/utils/index.ts
Additional comments not posted (6)
web/playwright.config.ts (6)

1-1: LGTM!

The import statement has been correctly updated to include devices from the Playwright library, which will enhance the configuration's capability to specify device settings for tests.


15-15: LGTM!

The snapshotPathTemplate property has been correctly added to specify the path template for storing snapshot files.


16-17: Verify the correctness of the new setup file.

The globalSetup property has been modified to point to a new setup file, ./e2e/auth.setup.ts, replacing the previous setup file. This change may reflect a shift in how the test environment is initialized, potentially indicating a more streamlined or updated setup process.

Ensure that the new setup file is correctly implemented and does not introduce any issues. Verify that the setup process works as expected and all necessary dependencies are properly initialized.


18-18: LGTM!

The reporter property has been correctly modified to conditionally use the "github" reporter in CI environments and the "list" reporter otherwise, which improves the reporting of test results based on the environment.


19-33: LGTM!

The new projects array has been correctly added, defining a project configuration for "chromium". The configuration utilizes the devices["Desktop Chrome"] settings and includes specific options for running tests, such as enabling screenshots and video recording during test execution.

The launchOptions have been adjusted to include arguments that disable the sandboxing feature, which may be necessary for certain environments.

Overall, these changes enhance the configuration's flexibility and usability, particularly for running tests across different environments.


28-29: Verify the impact of removing the commented-out launch arguments.

The launchOptions.args property includes a commented-out line with additional launch arguments:

// args: ["--headless","--no-sandbox","--use-angle=gl"]

It's important to ensure that removing the --headless and --use-angle=gl arguments does not introduce any issues or affect the test execution.

Verify that the tests still run correctly without these arguments and that there are no unintended side effects. If necessary, consider adding comments to explain why these arguments were removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants